import org.junit.Test;
import redis.clients.jedis.Jedis;

import java.util.List;
import java.util.Set;

/**
 * @author: wu linchun
 * @time: 2021/5/23 18:07
 * @description:
 */

public class Jedis_RedisTest {
    public static void main(String[] args) {
        Jedis jedis = new Jedis("192.168.1.2", 6379);
        //jedis.auth("19980319");
        String rs = jedis.ping();
        System.out.println("连接成功:" + rs);
        jedis.close();
    }

    //操作key String
    @Test
    public void demo1() {
        Jedis jedis = new Jedis("192.168.1.2", 6379);

        //设置单个key-value
        jedis.set("name", "张三");
        String name = jedis.get("name");
        System.out.println(name);

        //设置多个key-value
        jedis.mset("k1", "v1", "k2", "v2", "k3", "v3");
        List<String> mgetlist = jedis.mget("k1", "k2", "k3");
        for (String ss : mgetlist) {
            System.out.println(ss);
        }
        Set<String> keys = jedis.keys("*");//获取redis中所有的set
        for (String s : keys) {
            System.out.println(s);
        }
    }

    //操作list
    @Test
    public void demo2(){
        Jedis jedis = new Jedis("192.168.1.2", 6379);
        jedis.lpush("team1","张三","李四","王五");
        jedis.lpush("team2","赵六","刘七","关八");
        List<String> values=jedis.lrange("team1",0,-1);
        System.out.println(values.toString());
    }
}
